<template>
	<view>
		<view class="">1.页面传递数据(正向)</view>
		<button type="default" @click="toDetail01">01-detail01 navigate</button>

		<view class="">2.页面传递数据(逆向)</view>
		<button type="default" @click="toDetail02">01-detail02 navigate</button>

		<view class="">3.页面逆向传递数据(全局事件总线)</view>
		<button type="default" @click="toDetail03">01-detail03 navigate</button>
	</view>
</template>

<script setup>
	import {
		onLoad,
		onUnload
	} from '@dcloudio/uni-app'

	onLoad(() => [
		uni.$on('acceptDataV3', acceptDataV3)
	])

	onUnload(() => {
		uni.$off('acceptDataV3', acceptDataV3)
	})

	function acceptDataV3(value) {
		console.log('接收到detail03传递给页面的数据:', value);
	}

	function toDetail01() {
		uni.navigateTo({
			url: '/pages/09_setup_api/c-views/01_datail?name=goto01&id=001',
			success(res) {
				res.eventChannel.emit('acceptDataValue', {
					data: "acceptDataValue-name"
				})
			}
		})
	}

	function toDetail02() {
		uni.navigateTo({
			url: '/pages/09_setup_api/c-views/02_detail?name=goto02&id=002',
			events: {
				acceptDataV2(value) {
					console.log('接收到detail02传递过来的数据', value);
				}
			}
		})
	}

	function toDetail03() {
		uni.navigateTo({
			url: '/pages/09_setup_api/c-views/03_detail?name=goto03&id=003',
		})
	}
</script>

<style>

</style>